﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Register.IDAL;
using Register.DALFactory;
using Register.Command;

namespace Register.BLL
{
    /// <summary>
    /// FileName: DepartmentsBLL.cs
    /// CLRVersion: 4.0.30319.269
    /// Author: WangYan
    /// Corporation: 
    /// Description: 
    /// DateTime: 2012/6/27 11:58:51
    /// </summary>
   public class DepartmentsBLL
    {
       private static String typeNameKey = "IDepartmentsDALKey";

       public static Boolean AddDepartments(Model.DepartmentsInfo model)
       {
           IDepartmentsDAL iDepartmentsDAL = DALFactory<IDepartmentsDAL>.Create(typeNameKey);

           try
           {
               if (iDepartmentsDAL.AddDepartments(model) > 0)
                   return true;
               else
                   return false;
           }
           catch (Exception e)
           {
               LogRecordHelper.LogNote("ERROR",e.Message); 
               throw e;
           }
       }
       

       public static bool UpdateDepartments(Model.DepartmentsInfo model)
       {
           IDepartmentsDAL iDepartmentsDAL = DALFactory<IDepartmentsDAL>.Create(typeNameKey);
           try
           {
               if (iDepartmentsDAL.UpdateDepartments(model) > 0)
                   return true;
               else
                   return false;
           }
           catch (Exception e)
           {
               LogRecordHelper.LogNote("ERROR", e.Message); 
               throw e;
           }
       }

       public static bool DeleteDepartments(Model.DepartmentsInfo Info)
       {
           IDepartmentsDAL iDepartmentsDAL = DALFactory<IDepartmentsDAL>.Create(typeNameKey);
           try
           {
               if (iDepartmentsDAL.DeleteDepartments(Info) > 0)
                   return true;
               else
                   return false;
           }
           catch (Exception e)
           {
               LogRecordHelper.LogNote("ERROR", e.Message);
               throw e;
           }
       }

       public static int GetDepartmentsCount(string where)
       {
           IDepartmentsDAL iDepartmentsDAL = DALFactory<IDepartmentsDAL>.Create(typeNameKey);

           try
           {
               return iDepartmentsDAL.GetDepartmentsCount(where);
           }
           catch (Exception e)
           {
               LogRecordHelper.LogNote("ERROR", e.Message);
               throw e;
           }
       }

       public static List<Model.DepartmentsInfo> GetPagedDepartmentsInfo(int size, int pageIndex, string where)
       {
           IDepartmentsDAL iDepartmentsDAL = DALFactory<IDepartmentsDAL>.Create(typeNameKey);

           return iDepartmentsDAL.GetPagedDepartmentsInfo(size,pageIndex,where);

       }



    }
}
